<!DOCTYPE html>
<html ng-app="webapp">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>W9</title>
    <script src="js/angular-1.4.8.min.js"></script>
</head>

<body>
    <div layout="row">
        <div flex="28">
            <a href="#home" class="btn btn-success btn-lg">Home</a>
            <br>
            <a href="#about" class="btn btn-danger btn-lg">About</a>
        </div>
        <div flex="71" ng-controller="myCtrl">
            <!-- 例1 -->
          <form name="test_form" ng-init="o=[0,1,2,3]; a=o[1];">
            <select ng-model="a" ng-options="x for x in o" ng-change="s1()">
              <option value="">可以加这个空值</option>
            </select>

            <!-- 例2 -->
            <select ng-model="b" ng-options="x.productName group by x.mainCategory for x in clothes" ng-change="s2()">
              <option value="">可以加这个空值</option>
            </select>

            <!-- 例3 -->
            <form name="test_form" ng-controller="TestCtrl" ng-init="o={a: 0, b: 1}; a=o.a;">
                <select ng-model="c" ng-options="k for (k, v) in o" ng-change="s3()">
                    <option value="">可以加这个空值</option>
                </select>
            </form>

          </form>
        </div>
    </div>
</body>

</html>
<script type="text/javascript">
    var app = angular.module('webapp', []);
    app.controller('myCtrl', ['$scope', function($scope) {
        $scope.s1=(function(u){
            console.log($scope.a);
        });

        $scope.s2=(function(u){
            console.log($scope.b);
        });

        $scope.s3=(function(u){
            console.log($scope.c);
        });

        $scope.clothes = [{
                id: 10001,
                mainCategory: '男',
                productName: '水洗T恤',
                productColor: '白'
            }, {
                id: 10002,
                mainCategory: '女',
                productName: '圆领短袖',
                productColor: '黑'
            }, {
                id: 10003,
                mainCategory: '女',
                productName: '短袖短袖',
                productColor: '黃'
            }];

    }]);




</script>

